package com.yyds.service.impl;


import com.yyds.mapper.PersonResidentVoMapper;
import com.yyds.mapper.VaccineStatusMapper;

import com.yyds.pojo.VaccineStatus;
import com.yyds.service.VaccineStatusService;

import com.yyds.vo.EchartPieVo;
import com.yyds.vo.StatusInfoVo;
import com.yyds.vo.VaccineStatusVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service("vaccineStatusService")
public class VaccineStatusServiceImpl implements VaccineStatusService {

    @Autowired
    @Qualifier("personResidentVoMapper")
    private PersonResidentVoMapper personResidentVoMapper;

    @Autowired
    @Qualifier("vaccineStatusMapper")
    private VaccineStatusMapper vaccineStatusMapper;


    @Override
    public Integer insertVaccineStatusService(VaccineStatusVo vo) {
        Integer resident_id = personResidentVoMapper.queryVaccineIdMapper(vo.getResident_name());
        VaccineStatus vaccineStatus = new VaccineStatus();
        vaccineStatus.setResident_id(resident_id);
        vaccineStatus.setStatus_status(vo.getStatus_status());
        System.out.println("vaccineStatus = " + vaccineStatus);
        return vaccineStatusMapper.insertVaccineStatusMapper(vaccineStatus);
    }

    @Override
    public Integer deleteVaccineStatusService(Integer status_id) {
        return vaccineStatusMapper.deleteVaccineStatusMapper(status_id);
    }

    @Override
    public Integer deleteAllVaccineStatusService(String str) {
        String[] strs = str.split("-");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strs.length; i++) {
            list.add(Integer.parseInt(strs[i]));
        }
        return vaccineStatusMapper.deleteAllVaccineStatusMapper(list);
    }

    @Override
    public Integer updateVaccineStatusService(VaccineStatusVo vo) {
        VaccineStatus oldVaccineStatus = vaccineStatusMapper.querySimpleVaccineStatusMapper(vo.getStatus_id());
        VaccineStatus newVaccineStatus = new VaccineStatusVo();
        newVaccineStatus.setStatus_id(vo.getStatus_id());
        Integer resident_id = personResidentVoMapper.queryVaccineIdMapper(vo.getResident_name());
        newVaccineStatus.setResident_id(resident_id);
        newVaccineStatus.setStatus_status(vo.getStatus_status());
        return vaccineStatusMapper.updateVaccineStatusMapper(oldVaccineStatus, newVaccineStatus);
    }

    @Override
    public List<EchartPieVo> queryStatusStatusService() {
        return vaccineStatusMapper.queryStatusStatusMapper();
    }

    @Override
    public List<StatusInfoVo> queryStatusInfoVoService() {
        return vaccineStatusMapper.queryStatusInfoVoMapper();
    }
}
